package pile.customer.service.impl;

import pile.customer.entity.FrequentlyAskedQuestions;
import pile.customer.entity.User;
import pile.customer.mapper.FrequentlyAskedQuestionsMapper;
import pile.customer.service.IFrequentlyAskedQuestionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pile.customer.entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import pile.customer.utils.WebUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import pile.customer.entity.PageList;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;

import pile.customer.params.frequentlyAskedQuestions.DeleDTO;
import pile.customer.params.frequentlyAskedQuestions.ListDTO;

/**
 * <p>
 * 常见问题 服务实现类
 * </p>
 *
 * @author 郭天义
 * @since 2024-06-05
 */
@Service
public class FrequentlyAskedQuestionsServiceImpl extends ServiceImpl<FrequentlyAskedQuestionsMapper, FrequentlyAskedQuestions> implements IFrequentlyAskedQuestionsService {

    @Autowired
    private FrequentlyAskedQuestionsMapper frequentlyAskedQuestionsMapper;

    @Override
    public ResponseResult listPage(ListDTO listDTO) {
        IPage<FrequentlyAskedQuestions> iPage = new Page(listDTO.getPage(), listDTO.getLimit());

        //根据最后一次发送信息倒序查询  客服信息互通
        IPage data = frequentlyAskedQuestionsMapper.pageList(iPage, listDTO);
        PageList pageList = new PageList();
        pageList.setCount(data.getTotal());
        pageList.setLimit(data.getSize());
        pageList.setList(data.getRecords());
        pageList.setPage(data.getCurrent());
        pageList.setPages(data.getPages());
        return new ResponseResult(pageList);
    }

    @Override
    public ResponseResult dele(DeleDTO deleDTO) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.in(WebUtils.humpToLine("frequentlyAskedQuestionsId"), deleDTO.getIds());
        frequentlyAskedQuestionsMapper.delete(updateWrapper);
        return new ResponseResult(200, "删除成功");
    }

    @Override
    public ResponseResult add(FrequentlyAskedQuestions frequentlyAskedQuestions) {
        frequentlyAskedQuestionsMapper.insert(frequentlyAskedQuestions);
        return new ResponseResult(200, "新增成功");
    }

    @Override
    public ResponseResult info(Integer frequentlyAskedQuestionsId) {
        FrequentlyAskedQuestions frequentlyAskedQuestions = frequentlyAskedQuestionsMapper.selectById(frequentlyAskedQuestionsId);
        return new ResponseResult(frequentlyAskedQuestions);
    }

    @Override
    public ResponseResult edit(FrequentlyAskedQuestions frequentlyAskedQuestions) {
        frequentlyAskedQuestionsMapper.updateById(frequentlyAskedQuestions);
        return new ResponseResult(200, "更新成功");
    }

    /**
     * 点击有无帮助
     *
     * @param listDTO
     * @return
     */
    @Override
    public ResponseResult clickForHelp(ListDTO listDTO) {
        //问题ID不能为空
        if (listDTO.getFrequentlyAskedQuestionsId() == null) {
            return new ResponseResult(203, "问题ID不能为空");
        }
        //类型不能为空
        if (listDTO.getType()==null) {
            return new ResponseResult(203, "类型不能为空");
        }
        FrequentlyAskedQuestions frequentAskedQuestions =  getById(listDTO.getFrequentlyAskedQuestionsId());

        return null;
    }

    /**
     * 常见问题 用户端调用 需要放行 没token 列表
     * @param listDTO
     * @return
     */
    @Override
    public ResponseResult userList(ListDTO listDTO) {
        IPage<FrequentlyAskedQuestions> iPage = new Page(listDTO.getPage(), listDTO.getLimit());

        //根据最后一次发送信息倒序查询  客服信息互通
        IPage data = frequentlyAskedQuestionsMapper.pageList(iPage, listDTO);
        PageList pageList = new PageList();
        pageList.setCount(data.getTotal());
        pageList.setLimit(data.getSize());
        pageList.setList(data.getRecords());
        pageList.setPage(data.getCurrent());
        pageList.setPages(data.getPages());
        return new ResponseResult(pageList);
    }
}
